package com.sanrenzu.everybodytv.ui.vertical.radio;

import android.os.Handler;
import android.os.Looper;

import com.sanrenzu.everybodytv.bean.zxb.ZhiBoBean;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by My on 2016/9/7.
 */
public class RadioPresenter implements RadioContract.Presenter {

    private RadioContract.View view;
    private RadioContract.Modle modle;

    public RadioPresenter(RadioContract.View view){
        this.view =view;
        modle = new RadioModle();
    }

    @Override
    public void onGetZhiBoBean(String name) {
        modle.onGetZhiBoBean(name, new Callback<ZhiBoBean>() {
            @Override
            public void onResponse(Call<ZhiBoBean> call, Response<ZhiBoBean> response) {
                final ZhiBoBean bean = response.body();
                Handler handler  = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetZhiBoBean(bean);
                    }
                });
            }

            @Override
            public void onFailure(Call<ZhiBoBean> call, Throwable t) {
                Handler handler  = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetZhiBoBeanFailed("网络获取失败");
                    }
                });
            }
        });
    }
}
